package common;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BethaNode extends Node{
	private List<WorkingAlphaNode> workingParentAlphaNodes;
	private List<WorkingBethaNode> workingParentBethaNodes;
	private WorkingBethaNode workingBethaNode;
	private String operator;
	private Map<String, String> values;
	
	static int cont = 0;
	private int id;
	
	public BethaNode(){
		workingParentAlphaNodes = new ArrayList<WorkingAlphaNode>();
		workingParentBethaNodes = new ArrayList<WorkingBethaNode>();
		workingBethaNode = new WorkingBethaNode();
		workingBethaNode.setParentBethaNode(this);
		values = new HashMap<String, String>();
		id = cont++;
	}
	public List<WorkingAlphaNode> getWorkingParentAlphaNodes() {
		return workingParentAlphaNodes;
	}
	public void setWorkingParentAlphaNodes(List<WorkingAlphaNode> workingAlphaNodes) {
		this.workingParentAlphaNodes = workingAlphaNodes;
	}
	public WorkingBethaNode getWorkingBethaNode() {
		return workingBethaNode;
	}
	public void setWorkingBethaNode(WorkingBethaNode workingBethaNode) {
		this.workingBethaNode = workingBethaNode;
	}		
	public List<WorkingBethaNode> getWorkingParentBethaNodes() {
		return workingParentBethaNodes;
	}
	public void setWorkingParentBethaNodes(List<WorkingBethaNode> workingParentBethaNodes) {
		this.workingParentBethaNodes = workingParentBethaNodes;
	}
	public int getParentSize(){
		return workingParentAlphaNodes.size() + workingParentBethaNodes.size();
	}	
	public String getOperator() {
		return operator;
	}
	public void setOperator(String operator) {
		this.operator = operator;
	}
	public String toString(){
		String result = "(BethaNode_"+id+")";
		result += name + "\\ " + key + "=" + value + "\n\t\t\t" + workingBethaNode.toString();
		return result;
	}
	public String toString2(){
		String result = "(BethaNode_"+id+")";
		result += name + "\\ " + key + "=" + value;
		return result;
	}
	public List<Node> updateState(String key, String value){
		values.put(key, value);
		return checkCondition();
	}
	public List<Node> checkCondition(){
		if(operator == null && values.size() == getTotalValuesExpected())
		{			
			return workingBethaNode.updateState(values);
		}
		else if (operator != null)
		{
			System.out.println("[WARN] Por ahora no estamos usando operadores");
			return null;
		}
		else 
		{
			return null;
		}
	}
	public int getTotalValuesExpected(){
		int expected = 0;
		
		expected += workingParentAlphaNodes.size();
		
		for(WorkingBethaNode wb : workingParentBethaNodes){
			expected += wb.getTotalValuesExpected();
		}
		return expected;
	}

}
